#include "ZigbusIO.h"

ZigbusIO::ZigbusIO()
    : ZigbusItem(-1, IO_SIZE)
{
}

ZigbusIO::ZigbusIO(int value)
    : ZigbusItem(value, IO_SIZE)
{
}

ZigbusIO::ZigbusIO(const QString &strIO)
    : ZigbusItem(-1, IO_SIZE)
{
    bool ok = false;
    int value = strIO.mid(1).toInt(&ok);
    if(!ok) value = -1;
    if(strIO.mid(0, 1) == "S") { /* nothing to do */ }
    else if(strIO.mid(0, 1) == "A") { value += 100; }
    else { value = -1; }
    setValue(value);
}


ZigbusIO::ZigbusIO(const ZigbusIO &other)
    : ZigbusItem(other)
{
}

QString ZigbusIO::text() const
{
    if(getValue() < 0)
        return "";
    if(getValue() < 100)
        return "S"+QString::number(getValue());
    return "A"+QString::number(getValue() - 100);
}
